//全局配置
interface Config {
    port : number;
    frontendUrl : string;
    db: {
        host: string;
        user: string;
        password: string;
        database: string;
    };
    cloud:{
        validateUrl: string;
        clientId: string;
    }
}
export const config: Config = {
    port: parseInt(process.env.PORT, 3000),
    frontendUrl: process.env.FRONTEND_URL||'http://localhost:5173',
    db: {
        host: process.env.DB_HOST,
        user: process.env.DB_USER,
        password: process.env.DB_PASSWORD,
        database: process.env.DB_DATABASE,
    },
    cloud:{
        validateUrl: process.env.VALIDATE_URL,
        clientId: process.env.CLIENT_ID,
    }

}
//配置完整性检查
const requiredConfig = ['DB_HOST', 'DB_USER', 'DB_PASSWORD', 'DB_DATABASE', 'PORT', 'FRONTEND_URL', 'VALIDATE_URL', 'CLIENT_ID'];
requiredConfig.forEach((key) => {
    if (!process.env[key]) {
        throw new Error(`缺少配置项: ${key}`);
    }
})